import os
import sys
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
# from urllib import parse # parse.quote_plus() # @
import platform
from flask_cors import cross_origin
from flask_cors import CORS

if platform.system() == 'Windows':
    env_path = os.path.dirname(os.path.abspath(__file__)).split("\\python")[0] + "\\python\\com"
    sys.path.append(os.path.dirname(env_path))
elif platform.system() == 'Linux':
    env_path = os.path.relpath(__file__).split("python")[0] + "python/com"
    sys.path.append(os.path.dirname(env_path))


DB_URI = "mysql+pymysql://root:123456@localhost:3306/web"
SQLAlCHEMY_BINDS = {
    "soft_bind_key": "mysql+pymysql://root:123456@localhost:3306/web?charset=utf-8"
}

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = DB_URI
app.config["SQLAlCHEMY_BINDS"] = SQLAlCHEMY_BINDS
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_ECHO"] = True
CORS(app)

db = SQLAlchemy(app)
